package com.runshu.newsmartark.activity;

import android.os.Bundle;
import android.text.Html;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.runshu.newsmartark.R;
import com.runshu.newsmartark.adapter.PhyInfoAdapter;
import com.runshu.newsmartark.base.BaseActivity;
import com.runshu.newsmartark.entity.PhysicaInfoEntity;
import com.runshu.newsmartark.entity.PhysicalEntity;
import com.runshu.newsmartark.mvp.contract.PhysicaInfoContract;
import com.runshu.newsmartark.mvp.model.PhysicaInfoModel;
import com.runshu.newsmartark.mvp.presenter.PhysicaInfoPresenter;
import com.runshu.newsmartark.network.netbean.ResponseBean;
import com.runshu.newsmartark.util.common.ToastUtils;
import com.runshu.newsmartark.util.widget.TopTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Demo class
 *
 * @author yu
 * @date 2020/10/26
 * @decs：物流详细子页面
 */

public class PhysicaInfoActivity extends BaseActivity implements PhysicaInfoContract.View{
    @BindView(R.id.toolbar)
    TopTitleBar mToolbar;
    @BindView(R.id.img_wuliu)
    ImageView mImgWuliu;
    @BindView(R.id.tv_no)
    TextView mTvNo;
    @BindView(R.id.tv_company)
    TextView mTvCompany;
    @BindView(R.id.tv_root)
    TextView mTvRoot;
    @BindView(R.id.recy_phy)
    RecyclerView mRecyPhy;
    private List<PhysicaInfoEntity.NodesBean> mTraceList; //物流追踪列表的数据源
    private PhyInfoAdapter mAdapter;
    private String phyID;
    private PhysicaInfoPresenter infoPresenter;
    @Override
    protected int getLayoutId() {
        return R.layout.act_phyca_info;
    }

    @Override
    protected void initView() {
        mToolbar.setIsShowBac(true);
        mToolbar.setTitle("物流详情");
        phyID = getIntent().getStringExtra("phyID");
        infoPresenter = new PhysicaInfoPresenter(this, new PhysicaInfoModel());
    }

    @Override
    protected void initData() {
        mTraceList = new ArrayList<>();
        infoPresenter.getPhyInfo(phyID);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
        mAdapter = new PhyInfoAdapter(mTraceList);
        mRecyPhy.setLayoutManager(layoutManager);
        mRecyPhy.setAdapter(mAdapter);

    }

    @Override
    protected void bindListener() {

    }

    @Override
    protected void afterRequestPermission(int requestCode, boolean isAllGranted) {

    }

    @Override
    public void onGetPhyInfoSuccess(ResponseBean responseBean) {
        PhysicaInfoEntity infoEntity = (PhysicaInfoEntity) responseBean.pullData();
        mTvNo.setText("订单号: "  +infoEntity.getOrderNo());
        mTvCompany.setText( infoEntity.getExpCompanyName()+"|"+infoEntity.getExpNo());
        mAdapter.setNewData(infoEntity.getNodes());
    }

    @Override
    public void onError(String msg) {
        ToastUtils.showText(msg);
    }
}